<?php

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\ApiController;
use App\Services\Goods\GoodsSearchService;

class OpenSearchController extends ApiController
{

    protected $goodsSearchService;

    public function __construct(GoodsSearchService $goodsSearchService)
    {
        $this->goodsSearchService = $goodsSearchService;
    }

    public function lists()
    {

        $params = [
            'wid' => '8',
            'keyword' => '水果',
            'userRank' => '',
            'catIdList' => '',
            'catId' => '',
            'catChildId' => '',
            'origin' => '',
            'brandId' => '',
            'sortField' => '',
            'sortType' => '',
            'startOffset' => '',
        ];

        $this->goodsSearchService->config($params);

        try {
            $res['goods_list'] = $this->goodsSearchService->getSearchGoodsList();
            $res['brand_list'] = $this->goodsSearchService->getBrandList();
            $res['origin_list'] = $this->goodsSearchService->getOriginList();
            $res['category_list'] = $this->goodsSearchService->getCategoryId();
            $res['cat_child_list'] = $this->goodsSearchService->getCategoryId('get_son_category');

            return $this->success($res);

        } catch (\Exception $exception) {
            return $this->failed($exception->getMessage(), $exception->getCode());
        }

    }
}
